Digital computers have for many years employed registers as the lowest level in the hierarchy of computer storage devices. Registers have faster access time than main memory, but, because of cost, are few in number. The use of registers was at one time controlled directly by the machine language programmer. The use of registers is now controlled principally by another computer program, the compiler. The compiler transforms an easier to understand high level source language into the lower level object language of the machine. Part of this transformation task performed by the compiler is to place currently active data items in registers as much as possible. In this fashion, references to main memory are reduced, leading to faster overall performance. This task, called register allocation, is burdensome to the compiler program, resulting in compilers that are large and complex, awkward to maintain, and costly to prepare.
Computer instructions specify the data operands to be used in an arithmetic or logical operation through the use of addressing modes. An address is the common term used to describe the location in storage of a particular piece of data or an instruction. An addressing mode may, for example, specify that the data is to be found in a register, at an address specified in the instruction, or at an address contained in a particular register specified in the instruction. In a particularly common addressing mode, called "relative addressing" and found in many computers, the address of an operand is formed by adding the contents of a register to a constant specified in the instruction. This addressing mode is frequently used in the implementation of what is called a stack data structure. Because of this common use, the term "stack relative addressing" is frequently employed, and the particular register is called the stack pointer register.
Stack relative addressing is commonly used by compilers, using a data structure called a stack to allocate space in the computer's memory for local program variables, parameters, and temporary storage. Allocating space on a stack is advantageous because it provides a very simple and efficient technique for allocating space. The details of such a stack and how it is used by the compiler will not be discussed in more detail here; such details are common enough to be found in nearly any text on compiler design. One such book is "Principles of Compiler Design", by Messrs A. V. Aho and J. D. Ullman, Addison-Wesley Publishing Co., (1977).
Local variables for a procedure (i.e., variables to be used only in that procedure) are usually allocated on a stack. For a computer with registers, it is the job of the compiler program to move variables from the main memory into registers whenever possible to improve computer speed. Such register allocation is a difficult task for a compiler program and often requires more than one pass through a source program to allocate registers effciently. Furthermore, when one procedure is in the process of being executed and it is necessary to call another procedure, because the registers are limited in number, the contents of the registers must be saved in the main memory before the other procedure can be called. This process is called register saving. The registers are often saved on a stack, as mentioned above. Similarly, registers must be restored when returning to the calling procedure. Compiler program design would be greatly simplified and program execution would be faster if such register allocation was not required.
Computers without registers already exist and are know as memory-to-memory computers. A computer without such registers, however, incurs a penalty of reduced execution speed.